import React from 'react'
import { Table,message } from 'antd'
import styles from './noticeManage.css'
import {connect} from 'dva'
class NoticeTable extends React.Component{
    //勾选数据
    rowSelection = {
        onChange: (selectedRowKeys, selectedRows) => {
            const data = [];
            selectedRows.map(item =>{
                data.push(item.rowguid);
            })
            this.props.dispatch({
                type:'noticeManage/updateDelete',
                payload: data
            })
        },
    };
    //选择页码
    changePage =(page,pageSize)=>{
        this.props.dispatch({
            type:'noticeManage/queryPage',
            payload:{
                size: 10,
                start: page
            }
        })
    }
    //点击修改
    update =(data)=>{
        this.props.updateNotice(data);      
    }
    
    render(){
        const columns = [{
            title: '通知标题',
            dataIndex: 'republicName',
            key:'republicName',
        }, {
            title: '创建时间',
            dataIndex: 'udate',
            key: 'udate',
        }, {
            title: '浏览数',
            dataIndex: 'readNum',
            key: 'readNum',
        },{
            title: '详情',
            dataIndex:'1',
            key:'1',
            render: (text,record) =>
               <span onClick={()=>{this.update(record)}} className={styles.update}>修改</span>
        }];
        const {tableList,allCount} = this.props;
        return (
            <div className={styles.table}>
                <Table 
                    rowKey='id'
                    columns={columns}
                    rowSelection={this.rowSelection}
                    bordered={true}
                    dataSource={tableList}
                    pagination={{
                        total: allCount,
                        showTotal: total => `共有${allCount}条数据`,
                        onChange:this.changePage
                    }}
                />
            </div>
        )
    }
}
export default connect(({noticeManage})=>({noticeManage}))(NoticeTable)